package com.ff.controller;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ff.model.Fuser;
import com.ff.model.Shop;
import com.ff.model.Wares;

@Controller
@RequestMapping("/wares")
public class WaresContorller extends AllController {
	@RequestMapping("/cdselectall")//分页查询花数据
	public String cdselectall(ModelMap mm,int id) {
		int count=wservice.find_();
		mm.put("count", count);
		if(id<1)
			id=1;
		if(id>count)
			id=count;
		List<Wares> listff=wservice.find_limit(id);
		mm.put("wares", listff);
		mm.put("ts",id);
		return "f_wares";
	}
	
	@RequestMapping("/cdjumpinsert")//跳转到后台添加页面
	public String cdjumpinsert() {
		return "f_wares_insert";
	}
	
	@RequestMapping("/cdinsert")//后台添加数据
	public String cdinsert(Wares f) {
		String cd="wares";
		wservice.insert11(f);
		return "redirect:/fuser/cdjump00?cd="+cd;
				
	}
	
	@RequestMapping("/cdjumpupdate")//跳转到后台修改页面
	public String cdjumpupdate(ModelMap mm,int id) {
		Wares w=wservice.find11(id);
		mm.put("wares", w);
		return "f_wares_update";
	}
	
	@RequestMapping("/cdupdate")//后台修改数据
	public String cdupdate(ModelMap mm,Wares w) {
		String cd="wares";
		wservice.update11(w);
		return "redirect:/fuser/cdjump00?cd="+cd;
	}
	
	@RequestMapping("/cddelete")//后台删除数据
	public String cddelete(int id) {
		String cd="wares";
		wservice.delete01(id);
		return "redirect:/fuser/cdjump00?cd="+cd;
	}
	
	@RequestMapping("/jump00")//跳转到主页面
	public String jump00(ModelMap model,int sid) {
		Fuser f=fservice.find11(sid); 
		model.put("fuser",f);
		return "home";
	}
	

	
	@RequestMapping("/selall")//查询所有鲜花
	public String selall(ModelMap mm,int id) {
		List<Wares> list=wservice.select_();
		Fuser stu=fservice.find11(id);
		mm.put("wares", list);
		mm.put("fuser", stu);
		return "wares";
	}
	
	@RequestMapping("/spffname")//根据花名查询
	public String spffname(ModelMap mm,String username,int id) {
		if(username=="") {
			List<Wares> list=wservice.select_();
			mm.put("wares", list);
		}else {
			List<Wares> w=wservice.findffname(username);
			mm.put("wares", w);
		}
		Fuser f=fservice.find11(id);
		mm.put("fuser", f);
		return "wares";
	}
	
	@RequestMapping("/idff")//ID查询花
	public String idff(ModelMap mm,int id,int uid) {
		Wares w=wservice.find11(id);
		Fuser f=fservice.find11(uid);
		
		mm.put("fuser", f);
		mm.put("wares", w);
		return "wares_id";
	}
	
	@RequestMapping("/spff")//加入购物车
	public String spff(ModelMap mm,int fid,int id) {
		Shop s=sservice.find13(fid,id);
		Shop shop=new Shop();
		if(s==null||s.getStat()==1) {
			shop.setFid(fid);
			shop.setWid(id);
			shop.setSnumber(1);
			shop.setStat(0);
			sservice.insert11(shop);
			
		}else {
			shop=s;
			shop.setSnumber(s.getSnumber()+1);
			sservice.update11(shop);
		}
		
		return "redirect:/wares/jump00?sid="+fid;
	}
}
